package com.cke.yang.common.domain.model;

import lombok.Getter;
import lombok.Setter;

/**
 * Http接口返回模型
 *
 * @param <T> 返回结果数据类型
 * @author yuyang
 * @date  2025-11-18 00:00:00
 */
@Getter
@Setter
public class Result<T> {

    /**
     * 状态码
     */
    private String code;

    /**
     * 消息内容
     */
    private String msg;

    /**
     * 数据载体
     */
    private T data;

    private Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result<?> success() {
        return new Result<>("200", "success", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>("200", "success", data);
    }

    public static <T> Result<T> success(String code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> fail() {
        return new Result<>("500", null, null);
    }

    public static <T> Result<T> fail(String code, String msg) {
        return new Result<>(code, msg, null);
    }

    public static <T> Result<T> fail(String code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public boolean checkSuccess() {
        return "200".equals(code);
    }
}
